

#ifndef _MAPTHREADMGR_H
#define _MAPTHREADMGR_H
#include "CThreads.h"
#include "math/AlignedObjectArray.h"
namespace Apo
{
	//class MapMgr;
	typedef AlignedObjectArray<CThread*> ThreadSet;
	class SessionUpdaterThread;
	class SocketUpdaterThread;
	class ThreadMgr 
	{
	public:
		ThreadMgr();
		~ThreadMgr();

		void Initialize();
		void Shutdown();
		//void OnMapMgrCreated(MapMgr *mapMgr);
		void	AddThread(CThread *thread);
		void	RemoveThread(CThread *thread);
		int		GenerateThreadId();
		void	GetThreadById(int id); // slow!
		CThread* GetThreadByType(CThreadType type);
		// 	inline ThreadSet::iterator Begin() { return mThreads.begin(); }
		// 	inline ThreadSet::iterator End() { return mThreads.end(); }
		inline void SetBusy(bool val) { m_SetBusy = val; }
		String	ShowStatus();
		//void AppendThreadStatus(CThread* thread, std::stringstream &stream);
		void	PauseAllThreads();
		void	ResumeAllThreads();

		inline uint32 GetThreadCount() { return mThreads.size(); }
		
	private:
		ThreadSet	mThreads;
		int			ThreadIdCounter;
		bool		m_SetBusy;
		Mutex		_mutex;
	};
	extern ThreadMgr				*	gThreadMgr  ;
}
#endif
